{extend name="admin@index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">门诊列表</div>
    <div class="layui-card-body">
        <table class="layui-hide" id="currentTable" lay-filter="currentTable"
               data-auth-add="{:$auth->check('hospital.hospital/departmentAdd')}"
               data-auth-edit="{:$auth->check('hospital.hospital/departmentEdit')}"
               data-auth-delete="{:$auth->check('hospital.hospital/departmentDel')}"
        ></table>
    </div>
</div>

<script type="text/html" id="statusTypeTpl">
    <input type="checkbox" name="status" data-href='{:url("setstate2")}?id={{d.id}}' value="{{d.id}}" lay-skin="switch"
           lay-text="显示|隐藏" lay-filter="switchStatus" {{ d.status==1 ? 'checked' : '' }}>
</script>


<script type="text/html" id="barTool">
    {{# if(d.pid==0){ }}
    <a data-open='{:url("departmentAdd")}?pid={{ d.id }}&id={$hospital_id}'
       class="layui-btn layui-btn-xs layui-btn-normal"
       title="增加" data-full="true">增加</a>
    {{# } }}

    <a data-open='{:url("departmentEdit")}?id={{ d.id }}'
       class="layui-btn layui-btn-xs"
       title="编辑" data-full="true">编辑</a>

    <a href='{:url("departmentDel")}?ids={{ d.id }}'
       class="layui-btn layui-btn-danger layui-btn-xs layui-tr-del">删除</a>
</script>


<!--操作模板-->

{/block}
{block name="script"}
<script>
    var selectElement = null;
    layui.use('yznTable', function () {
        var table = layui.yznTable;
        var init = {
            table_elem: '#currentTable',
            table_render_id: 'currentTable',
            add_url: "{:url('departmentAdd')}?id={$hospital_id}",
            edit_url: "{:url('departmentEdit')}",
            delete_url: "{:url('departmentDel')}",
        };
        table.render({
            init: init,
            autoWidth: true,
            toolbar: ['refresh', 'add'],
            url: '{:url("DepartmentList")}?id={$hospital_id}',
            search:false,
            cols: [
                [
                    {field: 'id', width: '5%', title: 'ID'},
                    {field: 'name', align: "center", width: '40%', title: '医院/科室名称',templet: function (d) {
                            if (d.pid != 0) {
                                return  '&emsp;&emsp;&emsp;&emsp;'+d.name;
                            } else {
                                return  d.name;
                            }
                        }},
                    {field: 'sort', align: "center", width: '20%', title: '排序'},
                    {
                        field: 'status',
                        width: '15%',
                        align: "center",
                        title: '状态',
                        templet: '#statusTypeTpl',
                        unresize: true,
                        selectList: {0: '隐藏', 1: '显示'}
                    },
                    {fixed: 'right', align: "center", width: '20%', title: '操作', toolbar: '#barTool'}//delete'
                ]
            ],
            page: {}
        });
        yznTable.bindevent();
    });
</script>
{/block}